package com.glory.huaweipda.viewmodel

import android.app.Activity
import android.os.Handler
import androidx.databinding.ObservableArrayList
import com.glory.huaweipda.bean.EQPLotInfoBean
import com.glory.huaweipda.bean.EqpLogBean
import com.glory.huaweipda.model.TaskRepository
import com.glory.mvvmnet.base.BaseViewModel
import com.glory.mvvmnet.entity.CallObserveBean
import com.google.gson.JsonObject

class GetEQPLogModel : BaseViewModel() {
    var mfgItems = ObservableArrayList<EqpLogBean.Logmessagetextlist>()
    var s:String = ""
    private val repository  by lazy { TaskRepository() }

    lateinit var eQPLotInfoBean : EQPLotInfoBean
    //    var traclinArray = ObservableArrayList<TrackIn>()
    val Batch_TrackIn_Model = 1
//    var itemBinding = ItemBinding.of<EqpLogBean.Logmessagetextlist>(BR.eqpLog, R.layout.item_journal_layout)
    fun initAssets(context : Activity){



    }

    fun defaultGetEQPLotInfo(eqpid:String){

        val map = JsonObject()
        map.addProperty("eqpid", eqpid)

        launchOnlyResult({
            eQPLotInfoBean = repository.defaultdefaultGetEQPLotInfo(map)
            defUI.callObserve.value = CallObserveBean(Batch_TrackIn_Model, eQPLotInfoBean.get(0))
        })
    }

    fun defaultGetEQPLog(eqpID: String) {
        val map = JsonObject()
        map.addProperty("Eqpid", eqpID)
        map.addProperty("ISHISLOG", "Y")

        launchOnlyResult({
            val defaultGetEQPLog =
                repository.defaultGetEQPLog(map)
            if (defaultGetEQPLog!=null){
                mfgItems.clear()
                mfgItems.addAll(defaultGetEQPLog.logmessagetextlist.distinctBy { it.messageid })
                Handler().postDelayed({
                    defUI.callObserve.value = CallObserveBean(0)
                },3*1000)
            }
        },false)
    }

}

